package com.atguigu.common.result.result;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * ClassName:R
 * Package:com.atguigu.common.result
 * Description:
 *
 * @Author:77
 * @Create:2023/3/21 - 14:56
 * @Version:v1.0
 */
@Data
public class R {
    private Integer code;
    private String message;
    private Map<String,Object> date=new HashMap<>();
    private R() {}

    /*
    * 成功的结果
    * */
    public static R ok() {
        R r = new R();
      r.setCode(ResponseEnum.SUCCESS.getCode());
      r.setMessage(ResponseEnum.SUCCESS.getMessage());
      return r;
    }

    public static R error(){
        R r = new R();
        r.setCode(ResponseEnum.ERROR.getCode());
        r.setMessage(ResponseEnum.ERROR.getMessage());
        return r;
    }

    public static R setResult(ResponseEnum result){
        R r=new R();
        r.setMessage(result.getMessage());
        r.setCode(result.getCode());
        return r;
    }
    public R date(String key,Object value){
        this.date.put(key,value);
        return this;
    }
    public R date(Map<String,Object> map){
        this.setDate(map);
        return this;
    }
    public  R message(String message){
        this.setMessage(message);
        return this;
    }

    public  R code(Integer code){
        this.setCode(code);
        return this;
    }








}
